<% use_page_title "Groups" %>
<%= render layout: 'page_title' do %>
    <%= link_to("Add Group", new_group_path, :id => "new_group_button", :class => "btn btn-primary btn-small right") %>
<% end %>
<%= render layout: 'main_content' do %>
  <table class="data table table-rounded table-bordered table-hover table-striped">
    <thead>
      <tr>
        <th><%= link_to "Name", groups_path(:order => determine_order(params[:order], "#{Cms::Group.table_name}.name")) %></th>
        <th><%= link_to "Type", groups_path(:order => determine_order(params[:order], "#{Cms::GroupType.table_name}.name")) %></th>
        <th>Permissions</th>
      </tr>
    </thead>
    <% section_count = Cms::Section.count %>
    <% @groups.each do |g| %>
      <tr>
        <td>
            <%= link_to h(g.name), [:edit, g] %>
        </td>
        <td>
            <%= h(g.group_type.name) %>
        </td>
        <td>
          <% g.permissions.uniq.each do |p| %>
            - <%= p.full_name %> <br />
          <% end %>
          - <%= g.cms_access? ? "Edit" : "View" %>
          <%= g.sections.count >= section_count ? "All Sections" : "#{g.sections.count} of #{section_count} Sections" %>
        </td>
      </tr>
    <% end %>
  </table>
<% end %>
<% if @groups.total_pages > 1 %>
  <%= render_pagination @groups, Cms::Group %>
<% end %>